# 导入包
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
# 1.导入等待类
from selenium.webdriver.support.wait import WebDriverWait

# 获取浏览器驱动
driver = webdriver.Firefox()
driver.maximize_window()
# 设置隐式等待，针对于所有的元素有效
# driver.implicitly_wait(30)
# 打开测试的页面
url = 'file:///root/NSD2408/html/registerA.html'
driver.get(url)
# 2.创建等待对象，设置等待时长、查找频率
wait = WebDriverWait(driver, timeout=10, poll_frequency=0.5)
# 定位元素
username = wait.until(lambda x: x.find_element(By.CSS_SELECTOR, '#user'))
username.send_keys('admin')
# 定位元素
# username = driver.find_element(By.CSS_SELECTOR, '#user')
# username.send_keys('admin')

# 关闭浏览器
sleep(3)
driver.quit()